/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package battleshipgame.logic;

import battleshipgame.logic.Board.SquareStatus;
import battleshipgame.manager.GameManager;
import battleshipgame.logic.Board;
/**
 *
 * 
 */
public class Square {
    
    private boolean ShipSettable ; //chacks if it's allowed to set battleship in the square
    private SquareStatus status; // public enum SquareStatus {BATTLESHIP, BOMBED_BATTLESHIP, SEA, BOMBED_SEA }
    private Battleship battleship; // each square that contains part of a battleship keeps a refference to it.
       
    public Square() {
        this.ShipSettable = true;
        this.status = SquareStatus.SEA;
    }
    public boolean isShipSettable() {
        return ShipSettable;
    }
    public void setShipToBeUnsettable(){
        ShipSettable =false ;
    }
    public Battleship getMyBattleship() {
        return battleship;
    }
    public void setBattleship(Battleship myBattleship) /*throws Exception */ { //eliran update
            this.battleship = myBattleship;
            this.setStatus(SquareStatus.BATTLESHIP);
    }
    public void setStatus(SquareStatus status) { //eliran
        this.status = status;
    }
    public SquareStatus getStatus() {
        return status;
    }
//   public void UpdateSquareStatus( SquareStatus  newStatus){
//       this.status = newStatus;        
//   }
 public boolean Bomb ( Player attackedPlayer )throws AlreadyBombedException{
     //@eliran: maybe we should return the refference to the ship that was hurt... maybe not
     boolean flag = false ;
     switch (status)    {
         case BOMBED_BATTLESHIP:
         case BOMBED_SEA:
             flag = false;
             throw new AlreadyBombedException("Already bombed") ;
         case SEA://bomb failed
             status = SquareStatus.BOMBED_SEA ;
             flag = false;
             break;
         case BATTLESHIP: //bomb succeeded. 
             status = SquareStatus.BOMBED_BATTLESHIP ;
             battleship.DecreaseBattleshipHPByOne();
             if (battleship.IsBattleshipDead())
                 attackedPlayer.BattleshipWasDestroyed();
             flag = true;
             break;
     }
     return flag;
 }
}

